package geppetto.phraseTable.phrase.feature;

import java.util.HashMap;

public class CompositeFeature {
	public HashMap<String,AbstractFeature> _features = new HashMap<String,AbstractFeature>();
	public HashMap<String, Boolean> _printFeature = new HashMap<String, Boolean>();
	public HashMap<Integer, String> _featureOrder = new HashMap<Integer, String>();

	public CompositeFeature() {
		super();
	}
	
	public void addFeature(String name, AbstractFeature feature , int order){
		_features.put(name,feature);
		_printFeature.put(name, true);
		_featureOrder.put(order, name);
	}
	
	public void addFeature(String name, AbstractFeature feature, int order , boolean toPrint){
		_features.put(name,feature);
		_printFeature.put(name, toPrint);
		_featureOrder.put(order, name);
	}
	
	public String toMosesFormat(){
		String ret = "";
		for (String key : _featureOrder.values()){
			if(_printFeature.get(key)){
				AbstractFeature feature = _features.get(key);
				ret += feature.toMosesFormat() + " ";
			}
		}
		return ret;
	}
	
	public String getHeaders(){
		String ret = "";
		for (String key : _featureOrder.values()){
			if(_printFeature.get(key)){
				ret += key + " ";
			}
		}
		return ret;		
	}
	
	public void addAll(CompositeFeature features){
		_features.putAll(features._features);
		_printFeature.putAll(features._printFeature);
	}
	
	public void addAll(CompositeFeature features, int[] orders ,String[] indexes){		
		for(int i = 0; i < indexes.length; i++){
			String feature = indexes[i];
			addFeature(feature, features._features.get(feature), orders[i], features._printFeature.get(feature));
		}
	}
	
	public AbstractFeature getFeature(String name){
		return _features.get(name);
	}
}
